package com.yuexia.yxim.client.command;

import lombok.Data;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Scanner;

/**
 * ChatConsoleCommand
 *  聊天命令收集类
 * @author wjp
 * @date 2020/6/1
 */
@Data
@Slf4j
@Service
public class ChatConsoleCommand implements BaseCommand {

    private String toUserId;
    private String message;

    public static final String KEY = "2";

    @Override
    public void exec(Scanner scanner) {
        System.out.println("请输入聊天消息（id:message）");

        String[] info = null;

        while (true) {
            String input = scanner.next();
            info = input.split(":");
            if (info.length != 2) {
                System.out.println("消息格式错误,请输入聊天消息（id:message）");
            }else {
                break;
            }
            toUserId = info[0];
            message = info[1];
        }

    }

    @Override
    public String getKey() {
        return KEY;
    }

    @Override
    public String getTip() {
        return "发送聊天消息~";
    }
}
